package cn.itcast.xuesheng.dao.impl;

import cn.itcast.xuesheng.dao.ShowPageDao;
import cn.itcast.xuesheng.domain.Topic;
import cn.itcast.xuesheng.utils.JdbcUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository("showPageDao")
public class ShowPageDaoImpl implements ShowPageDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Override
    public Topic showPage(int tid) {
        String sql="SELECT * FROM topic WHERE tid=?";
        return jdbcTemplate.queryForObject(sql,new BeanPropertyRowMapper<Topic>(Topic.class),tid);
    }

    @Override
    public List<Topic> findthumb() {
        String sql="SELECT * FROM topic ORDER BY thumbup DESC";
        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<Topic>(Topic.class));
    }
}
